package com.neouton.crm.pm.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neouton.crm.enterprise.entity.EnterpriseVO;
import com.neouton.crm.entity.SysUserEntity;
import com.neouton.crm.pm.entity.*;
import com.neouton.crm.sales.entity.SalesFileRelationVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 *开票记录
 *回款记录
 */
@Mapper
public interface ManagerBrAndBmrMapper {

    /**
     * 保存开票申请
     * @param billingRecordVo
     */
    Integer saveBillingApply(@Param("vo") BillingRecordVo billingRecordVo);







    /**
     * 保存开票记录
     * @param billingRecordVo
     */
    Integer saveBillingRecord(@Param("vo") BillingRecordVo billingRecordVo);

    /**
     * 获取该项目中所有开票记录 / 开票申请
     * @param id
     * @return
     */
    List<ContractInfoVO> getProjectAllBillingRecord(Integer id,Integer billState);

    /**
     * 保存回款记录
     * @param backMoneyRecordVo
     */
    Integer saveBackMoneyRecord(@Param("vo") BackMoneyRecordVo backMoneyRecordVo);

    /**
     * 获取该项目中所有回款记录
     * @param id
     * @return
     */
    List<ContractInfoVO> getProjectAllBackMoneyRecord(Integer id);



    /**
     * 获取该项目该合同下对应期次的计划金额
     * @param projectManageId
     * @param contractId
     * @param period
     * @return
     */
    List<String> getbmpMoney(Integer projectManageId, Integer contractId, List<Integer> period);

    /**
     * 开票页面金额显示
     * @param projectManageId
     * @param contractId
     * @param period
     * @return
     */
    List<String> getreceiveMoney(Integer projectManageId, Integer contractId, List<Integer> period);

    /**
     * 回款记录金额显示
     * @param projectManageId
     * @param contractId
     * @param period
     * @return
     */
    List<String> getBmrReceiveMoney(Integer projectManageId, Integer contractId, List<Integer> period);

    /**
     * 获取附件
     * @param salesRelationId
     * @param fileClass
     * @return
     */
    List<SalesFileRelationVO> getSalesByBillingRecordId(Integer salesRelationId, Integer fileClass);

    /**
     * 查询所有回款计划
     * @return
     */
    List<BackMoneyPlanVo> getAllBackMoneyPlan();

    /**
     * 查询所有回款记录（审批通过）
     */
    List<BackMoneyRecordVo> getAllBackMoneyRecord();

    /**
     * 获取跟单视图回款、开票、已回金额汇总显示
     * @param projectID
     */
    ShowMoneyVo getSumAllMoneyShow(Integer projectID);

    /**
     * 获取责任人信息
     * @param liableId
     */
    SysUserEntity getUserInfo(Integer liableId);

    /**
     * 获取合同信息
     * @param contractId
     */
    ContractInfoVO getContractInfoById(Integer contractId);

    /**
     * 获取项目信息
     * @param projectManageId
     */
    SalesProjectManageVO getProjectManageInfoById(Integer projectManageId);

    /**
     * 获取项目中客户信息
     * @param customerId
     */
    EnterpriseVO getEnterpriseInfoById(Integer customerId);

    /**
     * 根据userID集合获取对应的邮箱
     * @param userIdList
     * @return
     */
    List<String> getUserEmailList(List<Integer> userIdList);

    /**
     * 修改回款计划
     * @param backMoneyPlanVo
     */
    void updateBackMoneyPlan( @Param("vo") BackMoneyPlanVo backMoneyPlanVo);



    /**
     * 修改开票申请
     * @param billingRecordVo
     */
    void updateBillApply(@Param("vo")BillingRecordVo billingRecordVo);

    /**
     * 获取该项目中的开票记录(state表示通过或者不通过)
     * @param id
     * @param state
     * @return
     */
    List<BillingRecordVo> getAllBillingApplyPeridName(Integer billState, Integer state);

    /**
     * 修改开票记录
     * @param billingRecordVo
     */
    void updateBillingRecord(@Param("vo") BillingRecordVo billingRecordVo);

    /**
     * 修改回款记录
     * @param backMoneyRecordVo
     */
    void updateBackMoneyRecord(@Param("vo")  BackMoneyRecordVo backMoneyRecordVo);


    BillingApplyDto searchBillingApplyByApprovalId(Integer approvalId);


    BillingRecordVo searchBillingRecordByApprovalId(Integer approvalId);

    /**
     * 根据approvalId 查询 回款记录页面
     * @param approvalId
     * @return
     */
    BackMoneyRecordVo searchBackMoneyRecordByApprovalId(Integer approvalId);

    /**
     * 查询合同是否通过
     * @param contractId
     * @return
     */
    ContractInfoVO ContractApplyPassOrNOByContractId(Integer contractId);

    /**
     * 根据合同id查询所有已经申请开票的期次
     * @param contractId
     * @return
     */
    List<String> getBillingApplyPeriod(Integer contractId,Integer billingRecordId,Integer state);

    List<String> getBackMoneyRecordPeriod(Integer contractId, Integer bmrId);

    /**
     * 修改回款计划 发票状态 / 回款状态
     * @param billingRecordVo
     * @param period
     */
    void updateBackMoneyIsbm(@Param("vo") BillingRecordVo billingRecordVo, Integer period,Integer isBilling);


    /**
     * 修改开票记录 回款状态
     */
    void updateBillingRecordIsbm(Integer billId, Integer isBm);

    /**
     * 记录开票申请备份表
     * @param billingRecordId
     * @param backUserId
     */
    void backUpBillingApply(@Param("billingRecordId") Integer billingRecordId, @Param("backUserId")Integer backUserId);

    /**
     * 记录开票记录备份表
     * @param billingRecordId
     * @param backUserId
     */
    void backUpBillingReord(@Param("billingRecordId") Integer billingRecordId, @Param("backUserId")Integer backUserId);

    /**
     * 回款记录备份表
     * @param bmrId
     * @param userId
     */
    void backupBackMoneyRecord(@Param("bmrId")Integer bmrId,@Param("backUserId") Integer userId);

    /**
     * 根据项目ID获取所有回款记录审批状态
     */
    List<BackMoneyRecordVo> queryBackMoneyRecordByProjectId(@Param("projectId") Integer projectId);

    /**
     * 根据项目ID获取所有开票记录审批状态
     */
    List<BillingRecordVo> queryBillingRecordByProjectId(@Param("projectId") Integer projectId);

    IPage<BackMoneyRecordVo> getBmrListByPage(@Param("page") IPage<BackMoneyRecordVo> page, @Param("backMoneyRecordVo") BackMoneyRecordVo backMoneyRecordVo, @Param("orderBy") String orderBy);

    IPage<BackMoneyRecordVo> getBmrApplyListByPage(@Param("page") IPage<BackMoneyRecordVo> page, @Param("backMoneyRecordVo") BackMoneyRecordVo backMoneyRecordVo, @Param("orderBy") String orderBy);

    List<BackMoneyRecordVo> getBmrList( @Param("backMoneyRecordVo") BackMoneyRecordVo backMoneyRecordVo);

    IPage<BillingApplyVo> getBarListByPage(@Param("page") IPage<BillingApplyVo> page, @Param("billingApplyVo") BillingApplyVo billingApplyVo,@Param("orderBy") String orderBy);

    List<BillingApplyVo> getBarList(@Param("billingApplyVo") BillingApplyVo billingApplyVo);

    IPage<BillingRecordVo> getBriListByPage(@Param("page")IPage<BillingRecordVo> page,@Param("billingRecordVo") BillingRecordVo billingRecordVo, @Param("orderBy") String orderBy);

    IPage<BillingRecordVo> getBriApplyListByPage(@Param("page")IPage<BillingRecordVo> page,@Param("billingRecordVo") BillingRecordVo billingRecordVo, @Param("orderBy") String orderBy);

    List<BillingRecordVo> getBriList(@Param("billingRecordVo")BillingRecordVo billingRecordVo);

    /**
     * 删除回款计划
     * @param backMoneyPlanVo
     */
    void deleteBackMoneyPlan(@Param("vo") BackMoneyPlanVo backMoneyPlanVo);

    Boolean judApprovalIdExists(Integer approvalId);

    BillingApplyDto searchBillingApplyBackByApprovalId(Integer approvalId);

    BillingRecordVo searchBillingRecordBackByApprovalId(Integer approvalId);

    Boolean jubBmRecordExists(Integer approvalId);

    BackMoneyRecordVo searchBackRecordBackByApprovalId(Integer approvalId);

   List<BackMoneyPlanVo>  getBackMoneyPlanByContractId(Integer contractId);

    void saveBackMoneyPlanBack( List<BackMoneyPlanBackEntity> list);

    List<BackMoneyPlanBackEntity> getBackMoneyPlanBackByApprovalId(Integer approvalId);

    //获取回款计划中 已申请金额集合
    List<String> getbillMoney(Integer projectManageId, Integer contractId, List<Integer> period);

    //多期次修改回款计划申请金额
    void updateBackMonryPlanBillMoney(Integer contractId, Integer period);
    ////修改lastPeriod期次对应的申请金额
    void updateBackMonryPlanBillMoneyByLastPeriod(Integer contractId, Integer lastPeriod,String billMoney );

    //根据合同id和期次查询回款计化
    BackMoneyPlanVo getBackMoneyPlanByContractIdAndPeriod(Integer contractId, Integer period);

    void updateBilling(Integer approvalId);
    //根据回款计划id获取回款计划金额
    String getBackMoneyBybmpId(Integer bmpId);

    //查询关系表金额
    List<String> getMoney(Integer bmpId);

    BillingApplyDto getBillingApply(Integer billingRecordId);

    void saveBackBillingMoney(@Param("list") List<BackBillingMoneyVo> backBillingMoneylist);

    List<BackBillingMoneyVo> getBackBillingMoneyByApprovalId(Integer approvalId);

    void backupBackBillingMoney(Integer approvalId, Integer backUserId);

    void deleteBackBillingMoneyByApprovalId(Integer approvalId);

    List<BackBillingMoneyVo> getBackBillingMoneyBackByApprovalId(Integer approvalId);
    //查询备份金额
    List<String> getMoneyBack(Integer bmpId);

    BackMoneyRecordVo getBackMoneyRecord(Integer bmrId);

    //根据回款计划id 查询关系表
    List<BackBillingMoneyVo> getBackBillingMoneyByBmpId(Integer bmpId);

    BillingRecordVo getBillingApplyisNoChoose(Integer billingRecordId);

    BillingRecordVo getBillingRecordisNoChoose(Integer billingRecordId);

    //获取对应回款计划下已回款金额
    List<String> getAlrBackMoneyBybmpId(Integer bmpId);

    IPage<BillingApplyVo> getBarApplyListByPage(@Param("page") IPage<BillingApplyVo> page, @Param("billingApplyVo") BillingApplyVo billingApplyVo,@Param("orderBy") String orderBy);

    List<BackMoneyPlanVo> searchBackMoneyPlanBycontractId(Integer id);

    List<ContractInfoVO> getProjectAllBackmoneyPlan();

    void deleteBillingById(Integer id);

    void deleteBackMoneyRecordById(Integer id);

}
